/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 // book count Tool tip  gosterimi için
 $(".book_count_tooltip").each(function() {
 var book_count_tooltip_elements = $(this);
 book_count_tooltip_elements.tooltip({'data-placement': 'top'});
 });
 */

var PRICE_FILTER_TYPE = 1;
var STOP_COUNT_FILTER_TYPE = 2;
var GO_DEPARTURE_TIME_FILTER_TYPE = 3;
var RETURN_DEPARTURE_TIME_FILTER_TYPE = 4;
var GO_ARRIVAL_TIME_FILTER_TYPE = 5;
var RETURN_ARRIVAL_TIME_FILTER_TYPE = 6;
var AIRLINE_COMPANY_FILTER_TYPE = 7;
var filterCriteriaObject = new Object();
$(document).ready(function() {

    var boardingairportInput = $("#boardingairport");
    boardingairportInput.select2({data: airports, minimumInputLength: 3, placeholder: "Gidiş", allowClear: true, matcher: function(term, text) {
            return text.toUpperCase().indexOf(term.toUpperCase()) == 0;
        }});
    $("#boardingairport").select2("val", session_search_criteria["boardingairpotCode"]);
    var landingairportInput = $("#landingairport");
    landingairportInput.select2({data: airports, minimumInputLength: 3, placeholder: "Dönüş", allowClear: true, matcher: function(term, text) {
            return text.toUpperCase().indexOf(term.toUpperCase()) == 0;
        }});
    landingairportInput.select2("val", session_search_criteria['landingairpotCode'])


    var returnDateInput = $("#return_date");
    var goDateInput = $("#go_date");
    var defaultGoDate = new Date();
    var currentDate = defaultGoDate;
    defaultGoDate.setDate(defaultGoDate.getDate() + 7);
    goDateInput.datepicker({
        showOn: "button",
        buttonImage: "/beyhan_fly/onlinefly/public_html/css/ico/calendar_small.jpg",
        buttonImageOnly: true,
        numberOfMonths: 2,
        minDate: new Date(),
        dateFormat: "dd/mm/yy",
        onSelect: function(date) {
            returnDateInput.datepicker("option", 'minDate', date);
        }});
    returnDateInput.datepicker({
        showOn: "button",
        buttonImage: "/beyhan_fly/onlinefly/public_html/css/ico/calendar_small.jpg",
        buttonImageOnly: true,
        numberOfMonths: 2,
        minDate: new Date(),
        dateFormat: "dd/mm/yy"
    });
    $(".return-departure-time-filter-container").hide();
    $(".return-arrival-time-filter-container").hide();
    if (session_search_criteria['directionOption'] != null) {
        if (session_search_criteria['directionOption'] == "2") {
            $("input:radio[name='flightdirection'][value='2']").attr("checked", "checked");
            goDateInput.datepicker("setDate", convertStringToDate("yy-mm-dd", session_search_criteria['goDate']));

            returnDateInput.datepicker("setDate", convertStringToDate("yy-mm-dd", session_search_criteria['returnDate']));
            returnDateInput.datepicker("option", 'minDate', convertStringToDate("yy-mm-dd", session_search_criteria['goDate']));

            $(".return-departure-time-filter-container").show();
            $(".return-arrival-time-filter-container").show();

        } else if (session_search_criteria['directionOption'] == "1") {
            $("input:radio[name='flightdirection'][value='1']").attr("checked", "checked");
            goDateInput.datepicker("setDate", convertStringToDate("yy-mm-dd", session_search_criteria['goDate']));
            returnDateInput.datepicker("setDate", convertStringToDate("yy-mm-dd", session_search_criteria['returnDate']));
            returnDateInput.datepicker("option", 'minDate', convertStringToDate("yy-mm-dd", session_search_criteria['goDate']));
            $(".return-date_row").hide();
        } else if (session_search_criteria['directionOption'] == "0") {
            $("input:radio[name='flightdirection'][value='0']").attr("checked", "checked");
            goDateInput.datepicker("setDate", convertStringToDate("yy-mm-dd", session_search_criteria['goDate']));
        }
    }

    $("#yetiskinNumber").find("option[value='" + session_search_criteria['yetiskinNumber'] + "']").attr("selected", "selected")
    $("#yetiskinNumber").selectBoxIt();
    $("#cocukNumber").find("option[value='" + session_search_criteria['cocukNumber'] + "']").attr("selected", "selected")
    $("select[name = cocukNumber]").selectBoxIt();

    $("#bebekNumber").find("option[value='" + session_search_criteria['bebekNumber'] + "']").attr("selected", "selected")
    $("select[name = bebekNumber]").selectBoxIt();
    var flightClassInput = $("#flight-class-select");
    var flightTypeInput = $("#flight-type-select");
    flightClassInput.select2();
    flightClassInput.select2("val", session_search_criteria['cabinClass']);
    flightTypeInput.select2();

    if (session_search_criteria['flightType'] == "1") {
        $("input[name=flight-type-checkbox]").attr("checked", "checked");
    }

    if (session_search_criteria['dateOption'] == "2") {//+/-3 gıun için
        $("input[name=flight-date-option-checkbox]").attr("checked", "checked");

    }
    $("input:radio[name='flightdirection']").click(function() {
        onflyDirecitonOptionClick($(this).val());
    });

    $(".fly-search-container").css("display", "block");
    setSearchFilterUI();
    setOtherDepartureJourneyEvent();
    setOtherArrivalJourneyEvent();
    setPriceDetailTriggerEvent();
    setBestPriceFlightTableEvent();
    setSearchDayNavigatorEvents();
    setSearchButtonEvent();
    setSearchNavDayEvent();
    setScrollEvents();

    $(".air-solution").each(function() {
        var airsolutionelement = $(this);
        airsolutionelement.find(".go-journey").first().find("input:radio").attr("checked", true);
        airsolutionelement.find(".return-journey").first().find("input:radio").attr("checked", true);
    });

    $(document).ajaxStop($.unblockUI);
});

function  setOtherDepartureJourneyEvent() {
    $(".other-departure-journey span").each(function() {
        var element = $(this);
        var air_price_solution_element = element.parents(".air-solution");
        var goJourneys = air_price_solution_element.find(".go-journey");
        element.click(function() {
            if (element.attr("clicked") === "clicked") {
                element.attr("class", "icon-circle-arrow-down");
                element.attr("clicked", "");
                var checkedRadioButton = air_price_solution_element.find(".go-journey input:checked");
                var selectedGoJourney = checkedRadioButton.parents(".go-journey");
                selectedGoJourney.siblings().hide(300);
            } else {
                element.attr("class", "icon-circle-arrow-up");
                element.attr("clicked", "clicked");
                if (air_price_solution_element.find(".filtered-departure-journey").size() > 0) {
                    air_price_solution_element.find(".filtered-departure-journey").show(200);
                } else {
                    goJourneys.show(300);
                }
            }
            goJourneys.promise().done(function() {
                air_price_solution_element.find(".not-filtered-departure-journey").hide();
            });
        });
    });
}

function setOtherArrivalJourneyEvent() {
    $(".other-arrival-journey span").each(function() {
        var element = $(this);
        var air_price_solution_element = element.parents(".air-solution");
        var returnJourneys = air_price_solution_element.find(".return-journey");
        element.click(function() {
            if (element.attr("clicked") === "clicked") {
                element.attr("class", "icon-circle-arrow-down");
                element.attr("clicked", "");
                var checkedRadioButton = air_price_solution_element.find(".return-journey input:checked");
                var selectedReturnJourney = checkedRadioButton.parents(".return-journey");
                selectedReturnJourney.siblings().hide(300);

            } else {
                element.attr("class", "icon-circle-arrow-up");
                element.attr("clicked", "clicked");
                if (air_price_solution_element.find(".filtered-return-journey").size() > 0) {
                    air_price_solution_element.find(".filtered-return-journey").show(200);
                } else {
                    returnJourneys.show(300);
                }
            }
        });
    });
}

function setPriceDetailTriggerEvent() {

    $(".price-detail-trigger").each(function() {
        var element = $(this);
        var air_price_solution_element = element.parents(".air-solution");
        var price_container_element = air_price_solution_element.find(".price-detail-container");
        element.click(function() {
            price_container_element.toggle('300');
            if (element.attr("triggered") == "triggered") {
                element.attr("class", "price-detail-trigger icon-chevron-down");
                element.attr("triggered", "");
            } else {
                element.attr("class", "price-detail-trigger icon-chevron-up");
                element.attr("triggered", "triggered");
            }
        });
    });
}

function setBestPriceFlightTableEvent() {
    var bestPriceElements = $(".header2");
    var airsoultionElements = $(".air-solution");
    var all_journeys = $(".journey");
    bestPriceElements.each(function() {
        var element = $(this);
        element.click(function() {
            var stopCount = 0;
            if (element.hasClass("no-stop")) {
                stopCount = 0;
            } else if (element.hasClass("one-stop")) {
                stopCount = 1;
            } else if (element.hasClass("more-stop")) {
                stopCount = 2;
            }

            var priceString = element.html();
            var matches = priceString.match(/\d+/);
            var minPrice = parseInt(matches[0]);

            var airline_company = element.attr("airlinecompany");
            //airsoultionElements.css("display", "block");
            if (element.hasClass("header2-clicked")) {
                filterCriteriaObject.airlineCompany = undefined;
                filterCriteriaObject.stopCount = undefined;

                element.removeClass("header2-clicked");
                $(".price-filter-input").slider("values", 0, parseInt(filter["min_price"]));
                /*
                 var thisJourney = $(".journey[airline-company!='" + airline_company + "']");
                 thisJourney.each(function() {
                 var theJourney = $(this);
                 theJourney.parents(".air-solution").css("display", "block");
                 });
                 */

            } else {
                filterCriteriaObject.airlineCompany = airline_company;
                filterCriteriaObject.stopCount = stopCount;
                $(".price-filter-input").slider("values", 0, minPrice);

                bestPriceElements.removeClass("header2-clicked");
                element.addClass("header2-clicked");
            }
        });

    });


}

function setSearchDayNavigatorEvents() {
    var prevDayLink = $(".prev-day-link");
    prevDayLink.click(function() {
        alert("prev");
    });
    var nextDayLink = $(".next-day-link");
    nextDayLink.click(function() {
        alert("next");
    });

}

function setSearchButtonEvent() {
    $("#searchButton").click(function() {
        var succesResponse = doflySearch(responseFlySearch);
    });
}

function  setSearchNavDayEvent() {
    $(".nav-icon").click(function() {
        var thisElement = $(this);
        var action = null;
        if (thisElement.hasClass("go-nav-prev-icon")) {
            action = "goprev";

        } else if (thisElement.hasClass("go-nav-next-icon")) {
            action = "gonext";

        } else if (thisElement.hasClass("return-nav-prev-icon")) {
            action = "returnprev";

        } else if (thisElement.hasClass("return-nav-next-icon")) {
            action = "returnnext"
        }
        if (action != null) {
            $.blockUI({message: $('#domMessage'), backgroundColor: "transparent"});
            var url = "searchnavday"
            var requestParam = {'action': action};
            $.post(url, requestParam, function(data) {
                responseFlySearch(data);
            }, "json");
        }

    });
}

function setSearchFilterUI() {
    setPriceFilterUI();
    setDepartureTimeFilterUI();
    setStopCountFilterUI();
    setAirlineCompanyFilterUI();
}

function setAirlineCompanyFilterUI() {
    $("input[name=airlineCompanyCodeCheckbox]").click(function() {
        var selectedAirlineCompanies = {};
        $("input[name=airlineCompanyCodeCheckbox]:checked").each(function() {
            var checkedElement = $(this);

            selectedAirlineCompanies[checkedElement.val()] = checkedElement.val();
        });
        filterCriteriaObject.selectedAirlineCompanies = selectedAirlineCompanies;
        onApplyFilter(AIRLINE_COMPANY_FILTER_TYPE, filterCriteriaObject);
    })
}
function setStopCountFilterUI() {
    $("input[name=stopCount]").click(function() {
        filterCriteriaObject.isNoStopExist = 0;
        filterCriteriaObject.isOneStopExist = 0;
        filterCriteriaObject.isTwoOrMoreExist = 0;
        $("input[name=stopCount]:checked").each(
                function() {
                    var checkedElement = $(this);
                    if (checkedElement.val() == 0) {
                        filterCriteriaObject.isNoStopExist = 1;
                    } else if (checkedElement.val() == 1) {
                        filterCriteriaObject.isOneStopExist = 1;
                    } else if (checkedElement.val() == 2) {
                        filterCriteriaObject.isTwoOrMoreExist = 1;
                    }
                }
        );
        onApplyFilter(STOP_COUNT_FILTER_TYPE, filterCriteriaObject);
    })
}


function setDepartureTimeFilterUI() {
    $(".go-departure-time-filter-container .info-value").html(convertMinutesToHoursString(filter['goDepartureTimeMinValue']) + "-" + convertMinutesToHoursString(filter['goDepartureTimeMaxValue']));

    $(".go-departure-time-filter-input").slider({
        range: true,
        min: parseInt(filter['goDepartureTimeMinValue']),
        max: parseInt(filter['goDepartureTimeMaxValue']),
        step: 15,
        values: [0, 1439],
        slide: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            $(".go-departure-time-filter-container .info-value").html(convertMinutesToHoursString(minMinute) + "-" + convertMinutesToHoursString(maxMinute));
        },
        change: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            filterCriteriaObject.goDepartureTimeMinValue = minMinute;
            filterCriteriaObject.goDepartureTimeMaxValue = maxMinute;
            onApplyFilter(GO_DEPARTURE_TIME_FILTER_TYPE, filterCriteriaObject);
        }

    });

    var returnDepartureTimeMinValue = session_search_criteria['directionOption'] == "2" ? parseInt(filter['returnDepartureTimeMinValue']) : 0;
    var returnDepaetureTimeMaxValue = session_search_criteria['directionOption'] == "2" ? parseInt(filter['returnDepartureTimeMaxValue']) : 1439;
    $(".return-departure-time-filter-container .info-value").html(convertMinutesToHoursString(returnDepartureTimeMinValue) + "-" + convertMinutesToHoursString(returnDepaetureTimeMaxValue));
    //filter['returnDepartureTimeMinValue']
    $(".return-departure-time-filter-input").slider({
        range: true,
        min: returnDepartureTimeMinValue,
        max: returnDepaetureTimeMaxValue,
        step: 15,
        values: [0, 1439],
        slide: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            $(".return-departure-time-filter-container .info-value").html(convertMinutesToHoursString(minMinute) + "-" + convertMinutesToHoursString(maxMinute));
        },
        change: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            filterCriteriaObject.returnDepartureTimeMinValue = minMinute;
            filterCriteriaObject.returnDepartureTimeMaxValue = maxMinute;
            onApplyFilter(RETURN_DEPARTURE_TIME_FILTER_TYPE, filterCriteriaObject);
        }

    });
    $(".go-arrival-time-filter-container .info-value").html(convertMinutesToHoursString(filter["goArrivalTimeMinValue"]) + "-" + convertMinutesToHoursString(filter["goArrivalTimeMaxValue"]));
    $(".go-arrival-time-filter-input").slider({
        range: true,
        min: parseInt(filter["goArrivalTimeMinValue"]),
        max: parseInt(filter["goArrivalTimeMaxValue"]),
        step: 15,
        values: [0, 1439],
        slide: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            $(".go-arrival-time-filter-container .info-value").html(convertMinutesToHoursString(minMinute) + "-" + convertMinutesToHoursString(maxMinute));
        },
        change: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            filterCriteriaObject.goArrivalTimeMinValue = minMinute;
            filterCriteriaObject.goArrivalTimeMaxValue = maxMinute;
            onApplyFilter(GO_ARRIVAL_TIME_FILTER_TYPE, filterCriteriaObject);

        }


    });
    var returnArrivalTimeMinValue = session_search_criteria['directionOption'] == "2" ? parseInt(filter['returnArrivalTimeMinValue']) : 0;
    var returnArrivalTimeMaxValue = session_search_criteria['directionOption'] == "2" ? parseInt(filter['returnArrivalTimeMaxValue']) : 1439;
    $(".return-arrival-time-filter-container .info-value").html(convertMinutesToHoursString(returnArrivalTimeMinValue) + "-" + convertMinutesToHoursString(returnArrivalTimeMaxValue));
    $(".return-arrival-time-filter-input").slider({
        range: true,
        min: returnArrivalTimeMinValue,
        max: returnArrivalTimeMaxValue,
        step: 15,
        values: [0, 1439],
        slide: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            $(".return-arrival-time-filter-container .info-value").html(convertMinutesToHoursString(minMinute) + "-" + convertMinutesToHoursString(maxMinute));
        },
        change: function(event, ui) {
            var minMinute = ui.values[0];
            var maxMinute = ui.values[1];
            filterCriteriaObject.returnArrivalTimeMinValue = minMinute;
            filterCriteriaObject.returnArrivalTimeMaxValue = maxMinute;
            onApplyFilter(RETURN_ARRIVAL_TIME_FILTER_TYPE, filterCriteriaObject);
        }

    });
}
function setPriceFilterUI() {
    var min = parseInt(filter["min_price"]); // filter global bir objedir  
    $(".price-filter-input").slider({
        range: true,
        min: min,
        max: parseInt(filter["max_price"]),
        values: [parseInt(filter["min_price"]), parseInt(filter["max_price"])],
        slide: function(event, ui) {
            $(".min-value").html(ui.values[ 0 ]);
            $(".max-value").html(ui.values[ 1 ]);

            // $( "#price_range_slider" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );     
        },
        change: function(event, ui) {
            filterCriteriaObject.minValue = ui.values[ 0 ];
            filterCriteriaObject.maxValue = ui.values[1];
            $(".min-value").html(ui.values[ 0 ]);
            $(".max-value").html(ui.values[ 1 ]);
            onApplyFilter(PRICE_FILTER_TYPE, filterCriteriaObject);
        }
    });

    $(".min-value").html($(".price-filter-input").slider("values", 0));
    $(".max-value").html($(".price-filter-input").slider("values", 1));
    //$( "#price_range_slider" ).val( "$" + $( "#price-filter-input" ).slider( "values", 0 ) +      " - $" + $( "#price-filter-input" ).slider( "values", 1 ) ); 

}

function onflyDirecitonOptionClick(value) {
    if (value == 2) {
        $(".return-date_row").show("300");
    } else if (value == 1) {
        $(".return-date_row").hide("300");
    } else if (value == 0) {
        //TODO openCokluUcusOption();
    }
}

//when Page is scrolled 
function setScrollEvents() {
    $(window).scroll(function() {
        /*
         var  newScrollTop = $(this).scrollTop();
         $(".left-container").stop();
         $(".left-container").animate({"marginTop":newScrollTop+10});
         */
        if ($(window).scrollTop() + $(window).height() > $(document).height() - 200) {

            var noScrolledAirPriceSolutions = $(".no-scrolled");
            if (noScrolledAirPriceSolutions.size() > 0) {
                $(".auto-loading-icon").css("display", "block");
                var count = 3;
                for (var i = 0; i < count; i++) {
                    var scrolledElement = noScrolledAirPriceSolutions.eq(i);
                    scrolledElement.removeClass("no-scrolled");
                    scrolledElement.addClass("scrolled");
                }
                $(".auto-loading-icon").css("display", "none");
                $(this).animate({scrollTop: newScrollTop - 200}, 200);
            }
        }
    });

}
function buidSearchFlightRequest() {
    var requestFlySearchJsonObject = {};
    requestFlySearchJsonObject['boardingairpotCode'] = $("#boardingairport").select2("val");
    requestFlySearchJsonObject['landingairpotCode'] = $("#landingairport").select2("val");
    requestFlySearchJsonObject['goDate'] = $.datepicker.formatDate("yy-mm-dd", $("#go_date").datepicker("getDate"));
    requestFlySearchJsonObject['returnDate'] = $.datepicker.formatDate("yy-mm-dd", $("#return_date").datepicker("getDate"));
    requestFlySearchJsonObject['yetiskinNumber'] = $("select[name=yetiskinNumber]").selectBoxIt().val();
    requestFlySearchJsonObject['cocukNumber'] = $("select[name = cocukNumber]").selectBoxIt().val();
    requestFlySearchJsonObject['bebekNumber'] = $("select[name = bebekNumber]").selectBoxIt().val();
    requestFlySearchJsonObject['dateOption'] = "1";
    if ($("input:checkbox[name = flight-date-option-checkbox]").attr("checked") == "checked") {
        requestFlySearchJsonObject['dateOption'] = "2";
    }


    requestFlySearchJsonObject['directionOption'] = $("input:radio[name=flightdirection]:checked").val();
    requestFlySearchJsonObject['cabinClass'] = $("#flight-class-select").select2("val");
    requestFlySearchJsonObject['flightType'] = "all";
    if ($("input:checkbox[name='flight-type-checkbox']") == "1") {
        requestFlySearchJsonObject['flightType'] = "1";
    }

    return requestFlySearchJsonObject;
}


function  doflySearch(_callback) {
    var requestFlySearchJsonObject = buidSearchFlightRequest();
    if (!validateSearchRequest(requestFlySearchJsonObject)) {
        return;
    }
    $.blockUI({message: $('#domMessage'), backgroundColor: "transparent"});
    var url = "searchflyrequest"
    $.post(url, requestFlySearchJsonObject, function(data) {

        responseFlySearch(data);

    }, "json");

}

function responseFlySearch(data) {
    if (data !== null && data.length > 0) {

        document.location.href = "searchresults";

    }
}
function validateSearchRequest(requestFlySearchJsonObject) {
    var valid = true;
    $(".boardingairpot-alert").hide();
    if (requestFlySearchJsonObject['boardingairpotCode'] == null || requestFlySearchJsonObject['boardingairpotCode'].length < 1) {
        valid = false;
        $(".boardingairpot-alert").show(100);
    }

    $(".landingairpot-alert").hide();
    if (requestFlySearchJsonObject['landingairpotCode'] == null || requestFlySearchJsonObject['landingairpotCode'].length < 1) {
        valid = false;
        $(".landingairpot-alert").show(100);
    }

    $(".godate-alert").hide();
    if (requestFlySearchJsonObject['goDate'] == null || requestFlySearchJsonObject['goDate'].length < 1) {
        valid = false;
        $(".godate-alert").show(100);
    }

    $(".returndate-alert").hide();
    if (requestFlySearchJsonObject['returnDate'] == null || requestFlySearchJsonObject['returnDate'].length < 1) {
        valid = false;
        $('.returndate-alert').show(100);
    }
    return valid;
}

function convertStringToDate(format, stringDate) {
    if (format == "yy-mm-dd") {
        var parsedDate = stringDate.split("-");
        var year = parsedDate[0];
        var month = parsedDate[1];
        month = month - 1
        var day = parsedDate[2];
        return new Date(year, month, day);
    }
}

function onApplyFilter(filterType, filterCriteriaObject) {
    var params = {};
    params.filterType = filterType;
    params.fiterCriteria = JSON.stringify(filterCriteriaObject);
    var url = "applyfilter";
    $(".auto-filter-loading-icon").show();
    $(".filter-request-message").hide();
    $.post(url, params, function(data) {
        if (data != null && data.error_code == "0000000") {
            applyFilterCallback(data.data);
        }
    }, 'json');

}

function applyFilterCallback(filteredAirPriceSolutionObjects) {
    var allAirSolutions = $(".air-solution");
    allAirSolutions.hide();

    if (filteredAirPriceSolutionObjects == null || !jQuery.isArray(filteredAirPriceSolutionObjects) || filteredAirPriceSolutionObjects.length < 1) {
        $(".filter-request-message").show();
        $(".auto-filter-loading-icon").show().delay(50).hide();
        return;
    }

    for (var i = 0; i < filteredAirPriceSolutionObjects.length; i++) {
        var filteredAirPriceSolutionObject = filteredAirPriceSolutionObjects[i];
        var combined_key = filteredAirPriceSolutionObject.combined_key;
        var combinedAirPriceSolutionContainer = $("#" + combined_key);
        combinedAirPriceSolutionContainer.show();
        var departure_journey_count = 0;
        var departure_journey_elements = departure_journey_elements = combinedAirPriceSolutionContainer.find(".go-journey");
        if (filteredAirPriceSolutionObject.filtered_departure_journeys_keys !== null && filteredAirPriceSolutionObject.filtered_departure_journeys_keys.length > 0) {
            if (filteredAirPriceSolutionObject.is_all_departures_journeys_filtered === false) {
                departure_journey_count = departure_journey_elements.size();
                departure_journey_elements.removeClass("filtered-departure-journey");
                departure_journey_elements.addClass("not-filtered-departure-journey");
                departure_journey_elements.each(function() {
                    var this_departure_journey_element = $(this);
                    for (k = 0; k < filteredAirPriceSolutionObject.filtered_departure_journeys_keys.length; k++) {
                        if (this_departure_journey_element.attr("id") === filteredAirPriceSolutionObject.filtered_departure_journeys_keys[k]) {
                            this_departure_journey_element.removeClass("not-filtered-departure-journey");
                            this_departure_journey_element.addClass("filtered-departure-journey");
                            break;
                        }
                    }
                });
                combinedAirPriceSolutionContainer.find(".filtered-departure-journey , .not-filtered-departure-journey").hide();
                 combinedAirPriceSolutionContainer.find(".filtered-departure-journey").first().find("input:radio").prop("checked",true);
                combinedAirPriceSolutionContainer.find(".filtered-departure-journey").first().show();
                var filteredJourneyElements = combinedAirPriceSolutionContainer.find(".filtered-departure-journey")

                if (filteredJourneyElements.size() == departure_journey_count) {

                } else if (filteredJourneyElements.size() === 1) {
                    combinedAirPriceSolutionContainer.find(".other-departure-journey").hide();
                } else if (filteredJourneyElements.size() > 1) {
                    combinedAirPriceSolutionContainer.find(".other-departure-journey").find("span").html("Diğer " + (filteredJourneyElements.size() - 1) + " seçenek");
                }

            } else {
                departure_journey_elements.removeClass("filtered-departure-journey");
                departure_journey_elements.removeClass("not-filtered-departure-journey");
                  departure_journey_elements.first().find("input:radio").prop("checked", true);
                departure_journey_elements.hide();
              
                departure_journey_elements.first().show();
                combinedAirPriceSolutionContainer.find(".other-departure-journey").show();
                combinedAirPriceSolutionContainer.find(".other-departure-journey").find("span").html("Diğer " + (departure_journey_elements.size() - 1) + " Gidiş");
            }
        }
        if (filteredAirPriceSolutionObject.filtered_return_journeys_keys != null && filteredAirPriceSolutionObject.filtered_return_journeys_keys.length > 0) {
            var returnJourneys = combinedAirPriceSolutionContainer.find(".return-journey");
            var returnJourneyCount = returnJourneys.size();
            if (filteredAirPriceSolutionObject.is_all_return_journeys_filtered == false) {

                returnJourneys.removeClass("filtered-return-journey");
                returnJourneys.addClass("not-filtered-return-journey");
                returnJourneys.each(function() {
                    var thisReturnJourney = $(this);
                    for (k = 0; k < filteredAirPriceSolutionObject.filtered_return_journeys_keys.length; k++) {
                        if (thisReturnJourney.attr("id") === filteredAirPriceSolutionObject.filtered_return_journeys_keys[k]) {
                            thisReturnJourney.removeClass("not-filtered-return-journey");
                            thisReturnJourney.addClass("filtered-return-journey");
                            break;
                        }
                    }
                });
                combinedAirPriceSolutionContainer.find(".filtered-return-journey, .not-filtered-return-journey").hide();
                combinedAirPriceSolutionContainer.find(".filtered-return-journey").first().find("input:radio").prop("checked",true);
                combinedAirPriceSolutionContainer.find(".filtered-return-journey").first().show();
                var filteredReturnJourneyElements = combinedAirPriceSolutionContainer.find(".filtered-return-journey");
                if (filteredReturnJourneyElements.size() == returnJourneyCount) {

                } else if (filteredReturnJourneyElements.size() === 1) {
                    combinedAirPriceSolutionContainer.find(".other-arrival-journey").hide();
                } else if (filteredReturnJourneyElements.size() > 1) {
                    combinedAirPriceSolutionContainer.find(".other-arrival-journey").find("span").html("Diğer " + (filteredReturnJourneyElements.size() - 1) + " Dönüş");
                }
            } else {
                returnJourneys.removeClass("filtered-return-journey");
                returnJourneys.removeClass("not-filtered-return-journey");
                  returnJourneys.first().find("input:radio").prop("checked",true);
                returnJourneys.hide();
              
                returnJourneys.first().show();
                combinedAirPriceSolutionContainer.find(".other-arrival-journey").show();
                combinedAirPriceSolutionContainer.find(".other-arrival-journey").find("span").html("Diğer " + (returnJourneyCount - 1) + " seçenek");

            }
        }
    }
    $(".auto-filter-loading-icon").show().delay(10).hide();
}


function convertMinutesToHoursString(minute) {
    var hours = Math.floor(minute / 60);
    minute = minute % 60;
    if (hours < 10) {

        hours = "0" + hours;
    }
    if (minute < 10) {
        minute = "0" + minute;
    }
    return hours + ":" + minute;
}



